﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Components;
using System.Windows.Forms;

namespace Core.Component
{
	public class SGVMainScreen:SGVScreen
    {
        private System.ComponentModel.IContainer components;
        private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
        private System.Windows.Forms.ToolStripMenuItem testToolStripMenuItem;
        public SGVToolbar sgvToolbar1;

        public SGVMainScreen():base()
        {
            InitializeComponent();
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(SGVMainScreen_FormClosing);
            //this.MaximizeBox = false;
        }

        void SGVMainScreen_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            if (module != null && module.Action != Base.ActionType.None)
            {
                MessageBox.Show("Vui lòng hoàn thành thao tác trước khi đóng module", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            if (keyData == System.Windows.Forms.Keys.F3)
            {
                if (sgvToolbar1.LIST.Enabled == true)
                    module.List();
                else
                    MessageBox.Show(String.Format("Không thể duyệt danh sách khi module đang ở trạng thái {0}",module.Action.ToString()),"Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            if (keyData == System.Windows.Forms.Keys.F4 && sgvToolbar1.NEW.Enabled == true)
                module.ActionNew();
            else if (keyData == System.Windows.Forms.Keys.F5 && sgvToolbar1.EDIT.Enabled == true)
                module.ActionEdit();
            else if (keyData == System.Windows.Forms.Keys.F6 && sgvToolbar1.DELETE.Enabled)
                module.ActionDelete();
            else if (keyData == System.Windows.Forms.Keys.F7 && sgvToolbar1.CANCEL.Enabled)
                module.ActionCancel();
            else if (keyData == System.Windows.Forms.Keys.F8 && sgvToolbar1.SAVE.Enabled)
                module.ActionSave();
            //else if (keyData == System.Windows.Forms.Keys.Escape)
            //    module.Close();

            return base.ProcessCmdKey(ref msg, keyData);
        }

        public override void RegisterModule(Base.BaseModule _module)
        {
            base.RegisterModule(_module);
            sgvToolbar1.RegisterModule(_module);
        }

        public void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.sgvToolbar1 = new Components.SGVToolbar();
            this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.testToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.contextMenuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // sgvToolbar1
            // 
            this.sgvToolbar1.Dock = System.Windows.Forms.DockStyle.Top;
            this.sgvToolbar1.Location = new System.Drawing.Point(0, 0);
            this.sgvToolbar1.Name = "sgvToolbar1";
            this.sgvToolbar1.SGVTag = null;
            this.sgvToolbar1.Size = new System.Drawing.Size(547, 35);
            this.sgvToolbar1.TabIndex = 0;
            // 
            // contextMenuStrip1
            // 
            this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.testToolStripMenuItem});
            this.contextMenuStrip1.Name = "contextMenuStrip1";
            this.contextMenuStrip1.Size = new System.Drawing.Size(97, 26);
            // 
            // testToolStripMenuItem
            // 
            this.testToolStripMenuItem.Name = "testToolStripMenuItem";
            this.testToolStripMenuItem.Size = new System.Drawing.Size(96, 22);
            this.testToolStripMenuItem.Text = "Test";
            // 
            // SGVMainScreen
            // 
            this.ClientSize = new System.Drawing.Size(547, 374);
            this.Controls.Add(this.sgvToolbar1);
            this.Name = "SGVMainScreen";
            this.contextMenuStrip1.ResumeLayout(false);
            this.ResumeLayout(false);

        }
    }
}
